<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="微信OpenID" prop="openId"
                :rules="[
                 ]">
              <el-input v-model="inputForm.openId" placeholder="请填写微信OpenID"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="邮箱" prop="email"
                :rules="[
                 ]">
              <el-input v-model="inputForm.email" placeholder="请填写邮箱"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="电话" prop="phone"
                :rules="[
                 ]">
              <el-input v-model="inputForm.phone" placeholder="请填写电话"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="用户昵称" prop="nickName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.nickName" placeholder="请填写用户昵称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="真实名称" prop="realName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.realName" placeholder="请填写真实名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="头像地址" prop="avatarUrl"
                :rules="[
                 ]">
              <el-input v-model="inputForm.avatarUrl" placeholder="请填写头像地址"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注" prop="memo"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.memo" placeholder="请填写备注"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import YxfpCustomerService from '@/api/invoice/customer/YxfpCustomerService'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          openId: '',
          email: '',
          phone: '',
          nickName: '',
          realName: '',
          avatarUrl: '',
          memo: ''
        }
      }
    },
    components: {
    },
    yxfpCustomerService: null,
    created () {
      this.yxfpCustomerService = new YxfpCustomerService()
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建客户管理`
        } else if (method === 'edit') {
          this.title = '修改客户管理'
        } else if (method === 'view') {
          this.title = '查看客户管理'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.yxfpCustomerService.queryById(this.inputForm.id).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.yxfpCustomerService.save(this.inputForm).then(({data}) => {
              this.visible = false
              this.$message.success(data)
              this.$emit('refreshDataList')
              this.loading = false
            }).catch(() => {
              this.loading = false
            })
          }
        })
      }
    }
  }
</script>

  
